﻿using System;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace StemServiceWebRole
{
    /// <summary>
    /// Provides various operations related to STEM123 application.
    /// </summary>
    [ServiceContract]
    public interface IStemService
    {
        /// <summary>
        /// Publishes metadata related to a publisher and term.
        /// </summary>
        /// <param name="publisher">Name of publisher.</param>
        /// <param name="term">Term of presentation.</param>
        /// <returns>Id of presentation, which is greater than zero else exception.</returns>
        [OperationContract]
        uint PublishMetadata(string publisher, string term);

        /// <summary>
        /// Uploads content related a presentation.
        /// </summary>
        /// <param name="presentationId">Id of presentation.</param>
        /// <param name="contentType">Type of content.</param>
        /// <param name="content">Array of bytes representing actual content.</param>
        /// <returns>Uri of uploaded content in the cloud.</returns>
        [OperationContract]
        Uri UploadContent(uint presentationId, ContentTypes contentType, byte[] content);

        /// <summary>
        /// Completes publishing of content after publishing metadata and uploading of content.
        /// </summary>
        /// <param name="presentationId">Id of presentation.</param>
        /// <param name="slides">Slides of presentation.</param>
        [OperationContract]
        void PublishContent(uint presentationId, Slide[] slides);

        /// <summary>
        /// Searches for presentations related to a term (and publisher).
        /// </summary>
        /// <param name="publisher">Name of publisher (optional).</param>
        /// <param name="term">Term to be searched.</param>
        /// <returns>Results of search.</returns>
        [OperationContract]
        SearchResults Search(string publisher, string term);
    }

    /// <summary>
    /// Slide of presentation.
    /// </summary>
    [DataContract]
    public class Slide
    {
        /// <summary>
        /// Question answered in slide.
        /// </summary>
        [DataMember]
        public string Question { get; set; }

        /// <summary>
        /// Type of media used to answer the question.
        /// </summary>
        [DataMember]
        public MediaTypes MediaType { get; set; }

        /// <summary>
        /// Duration of media in seconds.
        /// </summary>
        [DataMember]
        public uint MediaDuration { get; set; }

        /// <summary>
        /// Text of answer, if any.
        /// </summary>
        [DataMember]
        public string Answer { get; set; }

        /// <summary>
        /// Images used to answer, if any.
        /// </summary>
        [DataMember]
        public Uri ImageSource { get; set; }

        /// <summary>
        /// Media used to answer, if any.
        /// </summary>
        [DataMember]
        public Uri MediaSource { get; set; }
    }

    /// <summary>
    /// Presentation related to term, idea or concept.
    /// </summary>
    [DataContract]
    public class Presentation
    {
        /// <summary>
        /// Id of presentation.
        /// </summary>
        [DataMember]
        public uint Id;

        /// <summary>
        /// Date on which presentation was published.
        /// </summary>
        [DataMember]
        public DateTime PublishedOn { get; set; }

        /// <summary>
        /// Number of times, presentation has been viewed.
        /// </summary>
        [DataMember]
        public uint TimesViewed { get; set; }

        [DataMember]
        public Slide[] Slides { get; set; }
    }

    /// <summary>
    /// Results of search.
    /// </summary>
    [DataContract]
    public class SearchResults
    {
        /// <summary>
        /// Presentations found as result of a search.
        /// </summary>
        [DataMember]
        public Presentation[] Presentations;
    }

    /// <summary>
    /// Types of media supported in a slide.
    /// </summary>
    public enum MediaTypes : int
    {
        TextOnly = 0,
        TextWithImage,
        AudioOnly,
        AudioWithImage,
        Video
    }

    /// <summary>
    /// Type of media content which is supported.
    /// </summary>
    public enum ContentTypes : int
    {
        JPEG = 0,
        MP4,
        WAV
    }
}
